import {Component} from 'react';
import style from './index.css';
import propTypes from 'prop-types';
export class FormItemMy extends Component {
  constructor (props) {
    super (props);
    // console.log (props);
  }
  //  api
  // 属性： labelWidth label noComputWidth(不计算宽度)
  render () {
    let labelWidth = 66; //label宽度
    if (this.props.labelWidth) {
      labelWidth = this.props.labelWidth;
    }
    const {label, noComputWidth = false} = this.props || ''; //label 文案
    if (!label) {
      labelWidth = 0;
    }
    return (
      <div
        style={{paddingLeft: labelWidth + 14}}
        className={`${style.FormItem} ${noComputWidth ? style.noComputWidth : ''}`}
      >
        {label
          ? <div style={{width: labelWidth}} className={style.FormItem_label}>
              {label}
            </div>
          : ''}
        <div className={style.FormItem_label_con}>
          {this.props.children}
        </div>
      </div>
    );
  }
}

//判断类型
FormItemMy.propTypes = {
  label: propTypes.oneOfType ([propTypes.string, propTypes.number]),
  labelWidth: propTypes.number,
};

export default FormItemMy;
